package com.ventas.autopartes.action.user;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;
import java.sql.*;

/**
 * <p>
 * Validate a user login.
 * </p>
 */
public class Insert extends ActionSupport {

	public String execute() throws Exception {
		String url = "jdbc:mysql://localhost:3306/";
		String dbName = "prueba"; //"VentaAutopartes";
		String driverName = "org.gjt.mm.mysql.Driver";
		String userName = "root";
		String password = "860523";
		Connection con = null;
		Statement stmt = null;
		try {
			Class.forName(driverName).newInstance();
			con = DriverManager.getConnection(url + dbName, userName, password);
			stmt = con.createStatement();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		String uname = getUsername();
		String pws = getPassword();
		stmt = con.createStatement();
		int val = stmt.executeUpdate("INSERT employee VALUES (null,'" + uname+ "','" + pws + "')");
		if (val == 0) {
			return ERROR;
		} else {
			return SUCCESS;
		}
	}

	// ---- Username property ----

	/**
	 * <p>
	 * Field to store User username.
	 * </p>
	 * <p/>
	 */
	private String username = null;

	/**
	 * <p>
	 * Provide User username.
	 * </p>
	 * 
	 * @return Returns the User username.
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * <p>
	 * Store new User username
	 * </p>
	 * 
	 * @param value
	 *            The username to set.
	 */
	public void setUsername(String value) {
		username = value;
	}

	// ---- Username property ----

	/**
	 * <p>
	 * Field to store User password.
	 * </p>
	 * <p/>
	 */
	private String password = null;

	/**
	 * <p>
	 * Provide User password.
	 * </p>
	 * 
	 * @return Returns the User password.
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * <p>
	 * Store new User password
	 * </p>
	 * 
	 * @param value
	 *            The password to set.
	 */
	public void setPassword(String value) {
		password = value;
	}

}